Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
I am confused - I receive "getMonth is not a function"

even though i assigned a date to the variable, I receive the error message "getMonth is not a function"

Obviously the interpretor does not accept the type of date.

This is th relevant section of the code:

function init(){
            var m=document.getElementById("m");
            var d = Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();

yes, the function is terminated by a } there are more lines to it, but it stops exactly there.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You forgot to use new keyword with Date :

function init(){
  var m=document.getElementById("m");
  var d = new Date();
  refresh(d);
}


function refresh(d) {
  var month = d.getMonth();
  console.log(month)

}

init()

about 4 years ago · Juan Pablo Isaza Relatório

0

You seem to want to get the constructor, while you're currently defining the function as d.

Read more about Date here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

So, the code fragment should be:

function init(){
            var m=document.getElementById("m");
            var d = new Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();
about 4 years ago · Juan Pablo Isaza Relatório

0

Date is a class in javascript, so you need to use the new keyword to create a new instance and call methods like getMonth on it.

function init(){
            var m=document.getElementById("m");
            var d = new Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();
                console.log(month);
        }
        
        init();

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda